{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": "null",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "from matplotlib.animation import FuncAnimation\n",
    "fig, ax = plt.subplots()\n",
    "ln, = ax.plot([], [], '-',color='r', lw=1)\n",
    "time_template = 'LOVE = %.1fs'\n",
    "time_text = ax.text(0.05, 0.9, '', transform=ax.transAxes)\n",
    "def init():\n",
    "    ax.set_xlim(-3,3)\n",
    "    ax.set_ylim(-2, 3)\n",
    "    return ln,\n",
    "def update(ii):\n",
    "    xdata, ydata = [], []\n",
    "    for i in range(0,183):\n",
    "        xi=(182-i)/100\n",
    "        xdata.append(0.01*i-1.82)\n",
    "        yi=(xi**(2/3))+(0.9*(3.3-xi**2)**0.5)*np.cos(ii*(np.pi)*xi)\n",
    "        if type(yi)=='complex':\n",
    "            yi=np.around(abs(yi),decimals=4)\n",
    "        yi=np.around(yi, decimals=3)\n",
    "        ydata.append(yi)\n",
    "        \n",
    "    for i in range(0,182):\n",
    "        xi=i/100\n",
    "        xdata.append(xi) \n",
    "        yi=(xi**(2/3))+(0.9*(3.3-xi**2)**0.5)*np.cos(ii*(np.pi)*xi)\n",
    "        if type(yi)=='complex':\n",
    "            yi=np.around(abs(yi),decimals=4)\n",
    "        yi=np.around(yi, decimals=3)\n",
    "        ydata.append(yi)\n",
    "    ln.set_data(xdata, ydata)\n",
    "    time_text.set_text(time_template %(ii))\n",
    "    return ln,\n",
    "ani = FuncAnimation(fig, update, np.linspace(0, 13.14, 100),init_func=init, interval=100)\n",
    "ani.save('love.gif', writer='imagemagick', fps=60)\n",
    "plt.show()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
